package com.sx.gongzhong.adapter;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.gongzhong.R;
import com.sx.gongzhong.activity.LegalTypeSelectActivity;
import com.sx.gongzhong.model.LegalAdviceTypeBean;
import com.sx.gongzhong.widget.NoScrollGridView;
import java.util.List;

/**
 * Created by XZY on 2017/1/3.
 * 法律咨询类型选择的adapter
 */

public class LegalTypeSelectAdapter extends BaseQuickAdapter<LegalAdviceTypeBean,BaseViewHolder> {

    private Context context;

    public LegalTypeSelectAdapter(Context context, @LayoutRes int layoutResId,
                                  @Nullable List<LegalAdviceTypeBean> data) {
        super(layoutResId, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, final LegalAdviceTypeBean item) {
        helper.setText(R.id.tv_Title,item.getName());
        NoScrollGridView gridView =helper.getView(R.id.gridView);
        if (item.getChildren() !=null && item.getChildren().size() > 0) {
            LegalTypeAdapter adapter = new LegalTypeAdapter(context, R.layout.item_type_select_list, item.getChildren());
            gridView.setAdapter(adapter);
            adapter.getLegalType(new LegalTypeAdapter.LegalTypeCallback() {
                @Override
                public void getData(LegalAdviceTypeBean typesBean) {
                    Intent intent = new Intent();
                    intent.putExtra("typesBean",typesBean);
                    ((LegalTypeSelectActivity)context).setResult(Activity.RESULT_OK,intent);
                    ((LegalTypeSelectActivity)context).finish();
                }
            });
        }
    }
}
